package com.linq.cool.api.factory;

import com.linq.cool.api.dto.SysUserLastLoginDTO;
import com.linq.cool.api.feign.RemoteSysUserService;
import com.linq.cool.api.vo.LoginUser;
import com.linq.cool.common.core.domain.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Author: yqlin
 * @Date: 2021/1/17 05:11
 * @Description: 用户服务降级处理
 * @Version: 1.0.0
 */
@Slf4j
@Component
public class RemoteSysUserFallbackFactory implements FallbackFactory<RemoteSysUserService> {
    @Override
    public RemoteSysUserService create(Throwable throwable) {
        log.error("用户服务调用失败{}", throwable.getMessage());
        return new RemoteSysUserService() {
            @Override
            public Result<LoginUser> getUserInfo(String username) {
                return Result.fail("获取用户信息失败");
            }

            @Override
            public Result<?> updateLoginInfo(SysUserLastLoginDTO dto) {
                return Result.fail("更新用户信息失败");
            }

        };
    }
}
